﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Buecherverleih;
using MySql.Data.MySqlClient;




namespace Buecherverleih
{
    public partial class Form1 : Form
    {
        //Klassen / Globale Variablen
        string myConnectionStringGlobal = "SERVER=10.110.0.250;" +
                                "DATABASE=dbinventar;" +
                                "UID=dbinventar;" +
                                "PASSWORD=nX4NuFrh8EDPVM5X;";

        Panel BringMeToFront;
        Panel FocusMe;


        public Form1()
        {
            InitializeComponent();
        }


         /* 
          *  Insert Beispiel
          * 
          * MySqlConnection myConnection = new MySqlConnection(myConnectionStringGlobal);
            string myInsertQuery = "INSERT INTO dbbv_borrowers Values(1, 'Patrick Michiels')";
            MySqlCommand myCommand = new MySqlCommand(myInsertQuery);
            myCommand.Connection = myConnection;
            myConnection.Open();
            myCommand.ExecuteNonQuery();
            myCommand.Connection.Close();  
          
          
          */

        //Beim Start des Programms wird dies ausgeführt
        private void Form1_Load(object sender, EventArgs e)
        {
            pnl_login.BringToFront();
        }

        private void btn_showAll_Home_Click(object sender, EventArgs e)
        {
            pnl_Search_All.BringToFront();
            alleBuecherAnzeigen(0);
            erstelleBuecherMenue();
        }

        private void btn_showAll_main_Click(object sender, EventArgs e)
        {
                pnl_Search_All.BringToFront();
                alleBuecherAnzeigen(0);
                erstelleBuecherMenue();

            pnl_Search_All_Rows.Focus();
        }

        private void btn_Home_main_Click(object sender, EventArgs e)
        {
            pnl_Home.BringToFront();
        }

        private void btn_newBorrower_Click(object sender, EventArgs e)
        {
            pnl_newBorrower.BringToFront();
        }


        private void btn_newBorrower_save_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Benutzer anlegen?\n\nVorname: " +
                tbox_newBorrower_Firstname.Text + "\nNachname: " +
                tbox_newBorrower_Lastname.Text,
                "Speicherbestätigung",
                MessageBoxButtons.OKCancel);

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                MySqlConnection myConnection = new MySqlConnection(myConnectionStringGlobal);
                string myInsertQuery = "INSERT INTO dbbv_borrowers (borrower_familyname, borrower_firstname) Values('" +
                    tbox_newBorrower_Lastname.Text + "', '" + tbox_newBorrower_Firstname.Text + "')";
                MySqlCommand myCommand = new MySqlCommand(myInsertQuery);
                myCommand.Connection = myConnection;
                myConnection.Open();
                myCommand.ExecuteNonQuery();
                myCommand.Connection.Close();

                MessageBox.Show("Benutzer: " + tbox_newBorrower_Lastname.Text +
                    ", " + tbox_newBorrower_Firstname.Text + " angelegt!",
                    "Speicherbestätigung!",
                    MessageBoxButtons.OK);

                borrowerManagement_start();

            }
        }

        private void btn_borrowerManagement_Click(object sender, EventArgs e)
        {
            borrowerManagement_start();
        }

        public int countAllBorrowers()
        {
            int allBorrowersCounted = 0;
            //Verbindung zur Datenbank aufbauen
            //Methode mit Rückgabewert Alle Bücher zählen aufrufen
            MySqlConnection connection = new MySqlConnection(myConnectionStringGlobal);
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT COUNT(*) FROM dbbv_borrowers";
            MySqlDataReader Reader;
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                allBorrowersCounted = Convert.ToInt32(Reader.GetValue(0).ToString());
            }
            connection.Close();

            return allBorrowersCounted;
        }

        public int countAllBooks()
        {
            int allBooksCounted = 0;
            //Verbindung zur Datenbank aufbauen
            //Methode mit Rückgabewert Alle Bücher zählen aufrufen
            MySqlConnection connection = new MySqlConnection(myConnectionStringGlobal);
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT COUNT(*) FROM dbbv_books";
            MySqlDataReader Reader;
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                allBooksCounted = Convert.ToInt32(Reader.GetValue(0).ToString());
            }
            connection.Close();

            return allBooksCounted;
        }

        private void btn_borrowerEdit_Cancel_Click(object sender, EventArgs e)
        {
            pnl_borrowerManagement.BringToFront();
        }

        public void borrower_bearbeiten_Click(object sender, System.EventArgs e)
        {
            int borrowerID = 0;
            pnl_borrower_edit.BringToFront();

            borrowerID = Convert.ToInt32(((Button)sender).Name);

            tBox_borrowerEdit_ID.Text = borrowerID.ToString();

            MySqlConnection connection = new MySqlConnection(myConnectionStringGlobal);
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT * FROM dbbv_borrowers WHERE ID = " + borrowerID;
            MySqlDataReader Reader;
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                tBox_borrowerEdit_Lastname.Text = Reader.GetValue(1).ToString();
                tBox_borrowerEdit_Firstname.Text = Reader.GetValue(2).ToString();
            }
            connection.Close();
        }

        private void btn_borrowerEdit_Save_Click(object sender, EventArgs e)
        {
            MySqlConnection myConnection = new MySqlConnection(myConnectionStringGlobal);
            string myInsertQuery = "UPDATE dbbv_borrowers SET borrower_familyname='" + tBox_borrowerEdit_Lastname.Text + 
                "', borrower_firstname='" + tBox_borrowerEdit_Firstname.Text + "' WHERE ID = " + 
                tBox_borrowerEdit_ID.Text;
            MySqlCommand myCommand = new MySqlCommand(myInsertQuery);
            myCommand.Connection = myConnection;
            myConnection.Open();
            myCommand.ExecuteNonQuery();
            myCommand.Connection.Close();

            MessageBox.Show("Benutzer: " + tBox_borrowerEdit_Lastname.Text +
                ", " + tBox_borrowerEdit_Firstname.Text + " gespeichert!",
                "Speicherbestätigung!",
                MessageBoxButtons.OK);

            borrowerManagement_start();
        }

        private void btn_borrowerEdit_Erase_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Benutzer löschen?\n\nVorname: " +
                tBox_borrowerEdit_Firstname.Text + "\nNachname: " +
                tBox_borrowerEdit_Lastname.Text, 
                "Speicherbestätigung", 
                MessageBoxButtons.OKCancel);

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                Boolean loeschOK = true;
                string ausgelieheneBuecher = "";

                MySqlConnection connection2 = new MySqlConnection(myConnectionStringGlobal);
                MySqlCommand command2 = connection2.CreateCommand();
                command2.CommandText = "SELECT labelID FROM dbbv_books WHERE borrowed_by = " +
                    tBox_borrowerEdit_ID.Text;
                MySqlDataReader Reader2;
                connection2.Open();
                Reader2 = command2.ExecuteReader();
                while (Reader2.Read())
                {
                    ausgelieheneBuecher += Reader2.GetValue(0).ToString() + "\n";
                    loeschOK = false;
                }
                connection2.Close();


                if (loeschOK)
                {
                    MySqlConnection myConnection = new MySqlConnection(myConnectionStringGlobal);
                    string myDeleteQuery = "DELETE FROM dbbv_borrowers WHERE ID = " +
                        tBox_borrowerEdit_ID.Text;
                    MySqlCommand myCommand = new MySqlCommand(myDeleteQuery);
                    myCommand.Connection = myConnection;
                    myConnection.Open();
                    myCommand.ExecuteNonQuery();
                    myCommand.Connection.Close();

                    MessageBox.Show("Benutzer: " + tBox_borrowerEdit_Lastname.Text +
                        ", " + tBox_borrowerEdit_Firstname.Text + " gelöscht!",
                        "Löschbestätigung!",
                        MessageBoxButtons.OK);

                    borrowerManagement_start();
                }
                else
                {
                    MessageBox.Show("Der Benutzer kann nicht gelöscht werden, " + 
                        "da folgende Buecher von diesem ausgeliehen werden:\n\n" +
                        "LabelID(s):\n" + ausgelieheneBuecher,
                        "ERROR",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
        }

        private void btn_newBorrower_Click_2(object sender, EventArgs e)
        {
            tbox_newBorrower_Firstname.Text = "";
            tbox_newBorrower_Lastname.Text = "";
            pnl_newBorrower.BringToFront();
        }

        //wenn bei cBox_Nachname die Auswahl sich ändert wird diese Funktion ausgeführt
        private void cBox_Nachname_SelectedIndexChanged(object sender, EventArgs e)
        {
            //auf die textbox den Vornamen schreiben und vorher aus DB holen

            //Variable Nachname des selected Items und Variable für Anzahl des Vorkommens dieses
            string Nachname = cBox_Nachname.SelectedItem.ToString();
            int amountNachnamen = 0;

            //Count wie viele mit diesem Nachnamen
            MySqlConnection connection = new MySqlConnection(myConnectionStringGlobal);
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = " SELECT Count(*) FROM dbbv_borrowers WHERE borrower_familyname = '" +
                Nachname + "'";
            MySqlDataReader Reader;
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                amountNachnamen = Convert.ToInt32(Reader.GetValue(0).ToString());
            }
            connection.Close();

            if (amountNachnamen == 1)
            {
                MySqlConnection connection2 = new MySqlConnection(myConnectionStringGlobal);
                MySqlCommand command2 = connection2.CreateCommand();
                command2.CommandText = " SELECT borrower_firstname FROM dbbv_borrowers WHERE borrower_familyname = '" +
                    Nachname + "'";
                MySqlDataReader Reader2;
                connection2.Open();
                Reader2 = command2.ExecuteReader();
                while (Reader2.Read())
                {
                    tBox_Vorname.Text = Reader2.GetValue(0).ToString();
                }
                connection2.Close();
            }
            else
            {
                pnl_borrow_selectVorname.BringToFront();

                //Vermeiden von Mehrfachbeschreibung
                cBox_Vorname.Items.Clear();

                MySqlConnection connection3 = new MySqlConnection(myConnectionStringGlobal);
                MySqlCommand command3 = connection3.CreateCommand();
                command3.CommandText = " SELECT borrower_firstname FROM dbbv_borrowers WHERE borrower_familyname = '" +
                    Nachname + "'";
                MySqlDataReader Reader3;
                connection3.Open();
                Reader3 = command3.ExecuteReader();
                while (Reader3.Read())
                {
                    cBox_Vorname.Items.Add(Reader3.GetValue(0).ToString());
                }
                connection3.Close();
            }
        }

        private void cBox_Vorname_SelectedIndexChanged(object sender, EventArgs e)
        {
            pnl_borrow.BringToFront();
            tBox_Vorname.Text = cBox_Vorname.SelectedItem.ToString();
        }

        private void btn_borrowerMangement_main_Click(object sender, EventArgs e)
        {
            borrowerManagement_start();
        }

        private void btn_newBorrower_cancel_Click(object sender, EventArgs e)
        {
            pnl_borrowerManagement.BringToFront();
        }


        private void btn_newBook_main_Click(object sender, EventArgs e)
        {
            pnl_newbook.BringToFront();
        }

        private void btn_newBook_Cancel_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Abbrechen und zurück zum Home-Screen", 
                "Abbrechbestätigung", 
                MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                pnl_Home.BringToFront();
            }
        }

        private void btn_newBook_Home_Click(object sender, EventArgs e)
        {
            pnl_newbook.BringToFront();

            //Bei Aufruf des Panels alle Felder leeren
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
            richTextBox1.Text = "";
        }

        private void btn_newBook_main_Click_1(object sender, EventArgs e)
        {
            pnl_newbook.BringToFront();

            //Bei Aufruf des Panels alle Felder leeren
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
            richTextBox1.Text = "";
        }

        private void btn_borrowerManagement_Home_Click(object sender, EventArgs e)
        {
            borrowerManagement_start();
        }

        private void btn_book_Back_Click(object sender, EventArgs e)
        {
            BringMeToFront.BringToFront();
            FocusMe.Focus();
        }

        //Button Buch verleihen
        private void btn_BuchVerleihen_Click(object sender, EventArgs e)
        {
            // Prüfen, ob Ausleiher eingetragen
            if (cBox_Nachname.Text == "")
            {
                MessageBox.Show("Bitte Ausleiher auswählen!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                DialogResult result = MessageBox.Show("Möchten Sie dieses Buch ausleihen?\n\nBuchname: " +
                    tbox_DB_bookname.Text + "\nLabel_ID: " +
                    tbox_DB_labelID.Text, "Bestätigung",
                    MessageBoxButtons.OKCancel);
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    string borrowerID = "";
                    // Rausfinden welche ID hinter Nachname und Vorname steckt
                    MySqlConnection connection3 = new MySqlConnection(myConnectionStringGlobal);
                    MySqlCommand command3 = connection3.CreateCommand();
                    command3.CommandText = "SELECT ID FROM dbbv_borrowers WHERE borrower_familyname = '" +
                        cBox_Nachname.Text + "' AND borrower_firstname = '" + tBox_Vorname.Text + "'";
                    MySqlDataReader Reader3;
                    connection3.Open();
                    Reader3 = command3.ExecuteReader();
                    while (Reader3.Read())
                    {
                        borrowerID = Reader3.GetValue(0).ToString();
                    }
                    connection3.Close();

                    //zurückschreiben der Änderungen in Datenbank
                    MySqlConnection myConnection = new MySqlConnection(myConnectionStringGlobal);
                    string myDeleteQuery = "UPDATE dbbv_books SET isborrowed = 1, " +
                        "borrowed_by = " + borrowerID +
                        ", borrowed_on = '" + dt_Picker_borrowed_on.Value.Year.ToString() + 
                        "-" + dt_Picker_borrowed_on.Value.Month.ToString() + 
                        "-" + dt_Picker_borrowed_on.Value.Day.ToString() + "' " +
                        ", reserved = 0 " +
                        "WHERE ID = " + lbl_DB_ID.Text;
                    MySqlCommand myCommand = new MySqlCommand(myDeleteQuery);
                    myCommand.Connection = myConnection;
                    myConnection.Open();
                    myCommand.ExecuteNonQuery();
                    myCommand.Connection.Close();

                    // Bestätigung an Benutzer
                    MessageBox.Show("Buch wurde ausgeliehen!", "Speicherbestätigung", MessageBoxButtons.OK);

                    pnl_Search_All.BringToFront();

                    //mit vorher aufgerufenem Parameter wieder aufrufen
                    alleBuecherAnzeigen(Convert.ToInt32(lbl_restartNumberCallBookList.Text));
                    erstelleBuecherMenue();
                }
            }
        }

        //Speichern Button eine neuen Buches
        private void btn_newBook_Save_Click(object sender, EventArgs e)
        {
            //Überprüfen, ob in alle Felder etwas eingetragen wurde
            if (textBox1.Text == "" ||
                textBox2.Text == "" ||
                textBox3.Text == "" ||
                textBox4.Text == "" ||
                textBox6.Text == "" ||
                textBox7.Text == "" ||
                richTextBox1.Text == "")
            {
                //Warnmeldung
                MessageBox.Show("Bitte geben Sie in alle Felder etwas ein!",
                    "Warning",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
            }
            //Label ID muss unique sein!
            else
            {
                if (!checkLabel_isUnique())
                {
                    //Warnmeldung
                    MessageBox.Show("Diese LabelID ist bereits in Verwendung!\n" +
                        "Bitte wählen Sie eine einzigartige LabelID!",
                        "Warning",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                }
                else
                {
                    DialogResult result = MessageBox.Show("Sind alle Eingaben korrekt?",
                        "Speicherbestätigung",
                        MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Question);

                    if (result == System.Windows.Forms.DialogResult.OK)
                    {
                        MySqlConnection myConnection = new MySqlConnection(myConnectionStringGlobal);
                        string myInsertQuery = "INSERT INTO dbbv_books (labelID, " +
                            "name, content, type, publisher, theme, location, isborrowed)" +
                            "VALUES ('" + textBox2.Text + "'," +
                            "'" + textBox1.Text + "'," +
                            "'" + richTextBox1.Text + "'," +
                            "'" + textBox3.Text + "'," +
                            "'" + textBox4.Text + "'," +
                            "'" + textBox6.Text + "'," +
                            "'" + textBox7.Text + "'," +
                            "0)";

                        MySqlCommand myCommand = new MySqlCommand(myInsertQuery);
                        myCommand.Connection = myConnection;
                        myConnection.Open();
                        myCommand.ExecuteNonQuery();
                        myCommand.Connection.Close();


                        MessageBox.Show("Neues Buch angelegt!");


                        //Bücherliste anzeigen
                        pnl_Search_All.BringToFront();
                        alleBuecherAnzeigen(0);
                        erstelleBuecherMenue();
                    }
                }
            }
        }

        private void btn_eraseBook_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Moechten Sie dieses Buch wirklich löschen?",
                    "Löschbestätigung",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Question);

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                MySqlConnection myConnection = new MySqlConnection(myConnectionStringGlobal);
                string myDeleteQuery = "DELETE FROM dbbv_books " +
                    "WHERE ID=" + tbox_book_ID.Text;

                MySqlCommand myCommand = new MySqlCommand(myDeleteQuery);
                myCommand.Connection = myConnection;
                myConnection.Open();
                myCommand.ExecuteNonQuery();
                myCommand.Connection.Close();

                //Löschbestätigung
                MessageBox.Show("Buch wurde geloescht!");

                //Bücherliste anzeigen
                pnl_Search_All.BringToFront();
                alleBuecherAnzeigen(0);
                erstelleBuecherMenue();
            }
        }

        private void btn_searchPersons_Click(object sender, EventArgs e)
        {
            //Vorname leeren
            tbox_Vorname_Persons.Text = "";

            //Auflistung der Combobox hinzufügen
            MySqlConnection connection = new MySqlConnection(myConnectionStringGlobal);
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT borrower_familyname FROM dbbv_borrowers";
            MySqlDataReader Reader;
            connection.Open();
            Reader = command.ExecuteReader();
            cbox_Surname_Search.Items.Clear();

            while (Reader.Read())
            {
                cbox_Surname_Search.Items.Add(Reader.GetValue(0).ToString());
            }
            connection.Close();

            //Panel der Personensuche nach vorne holen
            pnl_searchPersons.BringToFront();
        }


        //wenn bei cbox_Surname_Search die Auswahl sich ändert wird diese Funktion ausgeführt
        private void cbox_Surname_Search_SelectedIndexChanged(object sender, EventArgs e)
        {
            //auf die textbox den Vornamen schreiben und vorher aus DB holen

            //Variable Nachname des selected Items und Variable für Anzahl des Vorkommens dieses
            string Nachname = cbox_Surname_Search.SelectedItem.ToString();
            int amountNachnamen = 0;

            //Count wie viele mit diesem Nachnamen
            MySqlConnection connection = new MySqlConnection(myConnectionStringGlobal);
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = " SELECT Count(*) FROM dbbv_borrowers WHERE borrower_familyname = '" +
                Nachname + "'";
            MySqlDataReader Reader;
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                amountNachnamen = Convert.ToInt32(Reader.GetValue(0).ToString());
            }
            connection.Close();

            if (amountNachnamen == 1)
            {
                MySqlConnection connection2 = new MySqlConnection(myConnectionStringGlobal);
                MySqlCommand command2 = connection2.CreateCommand();
                command2.CommandText = " SELECT borrower_firstname FROM dbbv_borrowers WHERE borrower_familyname = '" +
                    Nachname + "'";
                MySqlDataReader Reader2;
                connection2.Open();
                Reader2 = command2.ExecuteReader();
                while (Reader2.Read())
                {
                    tbox_Vorname_Persons.Text = Reader2.GetValue(0).ToString();
                }
                connection2.Close();
            }
            else
            {
                pnl_selectVorname_Search.BringToFront();

                //Vermeiden von Mehrfachbeschreibung
                cbox_Vorname_Search.Items.Clear();

                MySqlConnection connection3 = new MySqlConnection(myConnectionStringGlobal);
                MySqlCommand command3 = connection3.CreateCommand();
                command3.CommandText = " SELECT borrower_firstname FROM dbbv_borrowers WHERE borrower_familyname = '" +
                    Nachname + "'";
                MySqlDataReader Reader3;
                connection3.Open();
                Reader3 = command3.ExecuteReader();
                while (Reader3.Read())
                {
                    cbox_Vorname_Search.Items.Add(Reader3.GetValue(0).ToString());
                }
                connection3.Close();
            }
        }

        private void btn_search_main_Click(object sender, EventArgs e)
        {
            pnl_searchHome.BringToFront();
        }

        private void btn_search_Home_Click(object sender, EventArgs e)
        {
            pnl_searchHome.BringToFront();
        }

        private void btn_searchLabelID_Click(object sender, EventArgs e)
        {

            //Auflistung der Combobox hinzufügen
            MySqlConnection connection = new MySqlConnection(myConnectionStringGlobal);
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT labelID FROM dbbv_books";
            MySqlDataReader Reader;
            connection.Open();
            Reader = command.ExecuteReader();
            cbox_search_LabelID.Items.Clear();

            while (Reader.Read())
            {
                cbox_search_LabelID.Items.Add(Reader.GetValue(0).ToString());
            }
            connection.Close();


            pnl_search_Label.BringToFront();
        }

        //Button, der die Suche nach der (hoffentlich) ausgewählten Person started
        private void btn_searchGo_Persons_Click(object sender, EventArgs e)
        {
            // Prüfen, ob Person eingetragen
            if (cbox_Surname_Search.Text == "")
            {
                MessageBox.Show("Bitte Person auswählen!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //Panel nach vorne
                pnl_SearchPersons_Super.BringToFront();

                //Alle Bücher anzeigen, die von Person XY ausgeliehen wurden
                alleBuecherAnzeigen_ausgeliehenVonPerson(cbox_Surname_Search.Text,tbox_Vorname_Persons.Text);

                //Für Mausscrollen Main Panel fokussieren
                pnl_SearchPersons_Main.Focus();
            }
        }



        //Suchen Button, der nach Label-ID suchen lässt
        private void btn_searchLabel_Home_Click(object sender, EventArgs e)
        {
            // Prüfen, ob Label eingetragen
            if (cbox_search_LabelID.Text == "")
            {
                MessageBox.Show("Bitte LabelID eintragen!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //Panel nach vorne
                pnl_Search_Label_Super.BringToFront();

                //Das ausgewählte Buch anzeigen
                show_book_LabelID(cbox_search_LabelID.Text);

                //Für Mausscrollen Main Panel fokussieren
                pnl_Search_Label_Main.Focus();
            }
        }

        //Button, der aktuell alle ausgeliehenen Bücher anzeigt
        private void btn_searchAllLendBooks_Click(object sender, EventArgs e)
        {
            //Panel nach vorne
            pnl_searchAllLend.BringToFront();

            //Alle ausgewählten Bücher anzeigen
            showAllLendBooks(0);

            //Menü erstellen
            createAllLendBooksMenu();

            //Für Mausscrollen Main Panel fokussieren
            pnl_searchAllLend_Main.Focus();
        }

        private void btn_login_Click(object sender, EventArgs e)
        {
            login();
        }

        private void tbox_username_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
            {
                login();
            }
        }

        private void tbox_password_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                login();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Security.Cryptography.SHA512 shaM = System.Security.Cryptography.SHA512.Create();

            MySqlConnection myConnection = new MySqlConnection(myConnectionStringGlobal);
            string myDeleteQuery = "UPDATE dbbv_users SET password = '" +
                (BitConverter.ToString(
                            shaM.ComputeHash(
                            Encoding.Unicode.GetBytes((
                            "123" +
                            salt +
                            "demirarsland")))).Replace("-", "").ToLower()) + "' WHERE ID = 2";

            MySqlCommand myCommand = new MySqlCommand(myDeleteQuery);
            myCommand.Connection = myConnection;
            myConnection.Open();
            myCommand.ExecuteNonQuery();
            myCommand.Connection.Close();
        }

        private void btn_ChangeDefaultPW_Click(object sender, EventArgs e)
        {
            changedefaultpw();
        }

        private void tbox_ChangeDefaultpwPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
            {
                changedefaultpw();
            }
        }

        private void tbox_ChangeDefaultpwconfirmpw_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                changedefaultpw();
            }
        }

        private void btn_options_main_Click(object sender, EventArgs e)
        {
            startOptions();
        }

        private void btn_options_Home_Click(object sender, EventArgs e)
        {
            startOptions();
        }

        private void btn_borrowerStart_Click(object sender, EventArgs e)
        {
            borrowerManagement_start();
        }



    }
}
